<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
  <title></title>
  <link rel="stylesheet" href="/mobile/css/index.css" />
  <script src="/mobile/js/vue.js"></script>
  <script src="/mobile/js/vue-infinite-scroll.js"></script>
  <script src="/mobile/js/axios.min.js"></script>
  <script src="/mobile/js/vant.min.js"></script>
  <script src="/mobile/js/crypto-js.js"></script>
  <script src="/mobile/js/aes.js"></script>
  <script src="/mobile/js/common.js"></script>
  <style>
  * {
    margin: 0;
    padding: 0;
    -webkit-user-select: none;
    /* Safari */
    -moz-user-select: none;
    /* Firefox */
    -ms-user-select: none;
    /* IE10+/Edge */
    user-select: none;
    /* Standard syntax */
    list-style: none;
  }

  #app {
    padding: 10px;
    background: #05071D;
    min-height: 100vh;
    box-sizing: border-box;
/*    background-image: url("/mobile/img/top_bg.jpg");*/
    background-repeat: no-repeat;
    background-position: top center;
    background-size: contain;
  }
  .user-item {
    padding: 10px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .user-item:not(:last-child) {
    border-bottom: 1px solid #1A1C68;
  }

  .user-left {
    display: flex;
  }
  .user-info {
    margin-left: 15px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
  }
  .user-icon {
    width: 50px;
    height: 50px;
    border-radius: 5px;
    object-fit: cover;
  }
  .user-name {
    font-size: 14px;
    font-weight: bold;
    color: #fff;
  }
  .user-number {
    font-size: 12px;
    color: #A9ABCA;
  }
  .join-btn {
    height: 30px;
    margin-left: 10px;
  }
  .pretty-id {
    display: inline-block;
    background: #ff0000;
    color: #fff;
    font-size: 12px;
    padding: 0 2px;
    margin-right: 5px;
  }
  .user-right {
    display: flex;
  }
  .van-empty__image {
    width: 200px;
    height: 150px;
  }

  </style>
</head>

<body>
  <div id="app">
    <van-list v-model="loading" :finished="finished" :immediate-check="false" @load="getData">
      <template v-if="!list.length">
        <van-empty
          class="custom-image"
          image="/mobile/img/empty.png"
          description="暂无数据"
        />
      </template>
      <div v-else class="user-item" v-for="(item, index) in list" :key="index">
        <div class="user-left">
          <img class="user-icon" :src="item.avatar +'?x-oss-process=image/resize,h_120,m_fill'" alt="">
          <div class="user-info">
            <div class="user-name">{{item.userNickname}}</div>
            <div class="user-number"><span class="pretty-id">靓</span>{{item.goodNum}}</div>
          </div>
        </div>
        <div class="user-right">
          <van-button class="join-btn" color="linear-gradient(270deg, #9358F4 0%, #6E53F3 100%)" round @click="auditResolve(item.id)">同意</van-button>
          <van-button class="join-btn" color="#db3c3c" round @click="showRejectDialog(item.id)">拒绝</van-button>
        </div>
      </div>
    </van-list>
    <van-dialog v-model="showDialog" title="拒绝原因" show-cancel-button @confirm="auditReject" @cancel="closeDialog">
      <van-field v-model="auditResult" placeholder="请输入拒绝原因"  type="textarea" rows="4" maxlength="200" show-word-limit></van-field>
    </van-dialog>
  </div>
  <script>
  new Vue({
    el: '#app',
    data: {
      type: null,
      token: '',
      loading: false,
      finished: false,
      page: 1,
      limit: 20,
      list: [],
      showDialog: false,
      auditResult: ''
    },
    created() {
      const parse = (queryStr) => {
        const str = queryStr.replace(/^\?/, '')
        return str.split('&').reduce((pre, key) => {
          const [k, v] = key.split('=')
          pre[decodeURIComponent(k)] = decodeURIComponent(v)
          return pre
        }, {})
      }
      var data = parse(location.search)
      console.log(data)
      if (data.type && data.token) {
        document.title = data.type === '0' ? '签约审核' : '解约审核'
        this.type = Number(data.type)
        this.token = data.token
        this.getData()
      }
    },
    methods: {
      reloadData () {
        this.page = 1
        this.auditResult = ''
        this.list = []
        this.getData()
      },
      getData() {
        this.$toast.loading({
          overlay: true,
          forbidClick: true,
          duration: 0
        })
        request.post('/api/business/app/familyUser/getSignUserList', {
          page: this.page,
          limit: this.limit,
          queryType: this.type
        }).then(res => {
          console.log(res)
          if (this.loading) {
            this.list = []
            this.loading = false
          }

          this.list = this.list.concat(res.data.list)
          this.loading = false
          
          var list = res.data.list
          if (!list.length || this.list.length >= res.data.totalCount) {
            this.finished = true
          }
        }).finally(() => {
          this.$toast.clear()
          console.log(this.finished)
        })
      },
      auditResolve (id){
        // 审核通过-签约、解约
        var fn = this.type === 0 ? 'joinAudit' : 'exitAudit'
        this[fn](id, 1)
      },
      auditReject (){
        // 审核不通过-签约、解约
        var fn = this.type === 0 ? 'joinAudit' : 'exitAudit'
        this[fn](this.id, 0)
      },
      showRejectDialog (id) {
        this.id = id
        this.showDialog = true
      },
      joinAudit(id, type) {
        this.$toast.loading({
          overlay: true,
          forbidClick: true,
          duration: 0
        })
        request.post('/api/business/app/familyUser/audit', {
          id: id,
          isOpen: type,
          auditResult: this.auditResult
        }).then(res => {
          console.log(res)
          var that = this
          this.$toast({
            message: '操作成功',
            duration: 1500,
            onClose() {
              that.reloadData()
            }
          })
        }).finally(() => {
          this.$toast.clear()
        })
      },
      exitAudit(id, type) {
        this.$toast.loading({
          overlay: true,
          forbidClick: true,
          duration: 0
        })
        request.post('/api/business/app/familyUser/quitAudit', {
          id: id,
          isOpen: type,
          auditResult: this.auditResult
        }).then(res => {
          this.$toast.clear()
          console.log(res)
          var that = this
          this.$toast({
            message: '操作成功',
            duration: 1500,
            onClose() {
              that.reloadData()
            }
          })
        }).catch(() => {
          this.$toast.clear()
        })
      },
      closeDialog () {
        this.showDialog = false
        this.auditResult = ''
      }
    }
  })
  </script>
</body>

</html>